#include <iostream>

class Car
{
public:
    virtual void create() = 0;
};

class BENZ:public Car
{
public:
    void create()
    {
        std::cout<<"创建一辆奔驰"<<std::endl;
    }
};

class BMW:public Car
{
public:
    void create()
    {
        std::cout<<"创建一辆宝马"<<std::endl;
    }
};

class BYD:public Car
{
public:
    void create()
    {
        std::cout<<"创建一辆比亚迪"<<std::endl;
    }
};

//抽象工厂类
class Factory
{
public:
    virtual Car* CreateCar() = 0;
};

//具体工厂类
class BenzFactory:public Factory
{
public:
    virtual Car* CreateCar()
    {
        return new BENZ();
    }
};
class BMWFactory:public Factory
{
public:
    virtual Car* CreateCar()
    {
        return new BMW();
    }
};
class BYDFactory:public Factory
{
public:
    virtual Car* CreateCar()
    {
        return new BYD();
    }
};

class Factory2
{
public:
    Factory * CreateBMWFactory()
    {
        return new BMWFactory;
    }
};


int main()
{
    Factory2 f2;
    Factory *f  = f2.CreateBMWFactory();
    Car *c = f->CreateCar();
    c->create();
}